package com.yw.fileupload.upload.web.controller;

import com.yw.fileupload.upload.service.FileUploadService;
import com.yw.fileupload.upload.util.file.FileExtUtils;
import com.yw.fileupload.upload.util.file.FilePanDuan;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author hbw
 * @create 2021-04-26 20:33
 */

@RestController
@RequestMapping("/upload")
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;

    @ApiOperation(value = "上传至本地")
    @PostMapping("/native")
    public String nativeFile(@ApiParam(name = "file",value = "文件",required = true) MultipartFile file,
                             String token){


        /**
         * 校验
         */
        FilePanDuan.aaa(file,token);

        /**
         * 返回文件名
         */
        String s = fileUploadService.nativeFile(file);

        return s;
    }

    @PostMapping("/oss")
    public String aliyunOss(@ApiParam(name = "file",value = "文件",required = true) MultipartFile file,
                            @ApiParam(name = "token",value = "唯一ID",required = true) String token){

        /**
         * 校验
         */
        FilePanDuan.aaa(file,token);
        String s = fileUploadService.aliyun(file);
        return s;
    }


}
